package gw.com.android.ui.trade.Fragment;

import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.gwtsz.android.rxbus.RxBus;
import com.gwtsz.gts2.hx.R;

import org.json.JSONException;

import butterknife.BindView;
import butterknife.OnClick;
import gw.com.android.app.AppContances;
import gw.com.android.app.AppMain;
import gw.com.android.app.GTConfig;
import gw.com.android.model.ConfigType;
import gw.com.android.model.ConfigUtil;
import gw.com.android.model.DataManager;
import gw.com.android.presenter.TradePresenter;
import gw.com.android.terminal.AppTerminal;
import gw.com.android.terminal.GTSDataListener;
import gw.com.android.ui.dialog.PopupConfirmDialog;
import gw.com.android.ui.trade.TradeBusiness;
import gw.com.android.ui.trade.TradeOrderActivity;
import gw.com.android.ui.trade.TradeProductPopWindow;
import gw.com.android.ui.trade.TradeRangeModel;
import gw.com.android.ui.trade.TradeTypePopWindow;
import gw.com.android.ui.views.NumericEdit;
import gw.com.android.ui.views.OrderBottomView;
import gw.com.android.ui.views.TitleRangeView;
import gw.com.jni.library.terminal.GTSConst;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import www.com.library.app.Logger;
import www.com.library.model.DataItemDetail;
import www.com.library.util.DoubleConverter;
import www.com.library.util.StringFormatter;
import www.com.library.view.NumberInput;
import www.com.library.view.RecyclerClickListener;

/**
 * 挂单下单界面
 * @author reeta.zou
 *
 */
public class PendingOrderFragment extends BaseOrderFragment {

	/**产品列表视图*/
	@BindView(R.id.proNameLayout)
	View mPrdNameLayout;
	/**产品列表*/
	@BindView(R.id.proNameView)
	TextView mPrdNameView;
	/**下单类型视图*/
	@BindView(R.id.trade_type_Layout)
	View typeLayout;
	/**下单类型视图*/
	@BindView(R.id.trade_type)
	TextView typeView;
	/**有效期类型视图*/
	@BindView(R.id.expire_typeLayout)
	View expireTypeLayout;
	/**有效期类型视图*/
	@BindView(R.id.expire_type)
	TextView expireTypeView;
	/**手数加减器*/
	@BindView(R.id.morder_input_lot)
	NumericEdit m_lotEditView = null;
	/**价格加减器*/
	@BindView(R.id.morder_input_price)
	NumericEdit m_priceEditView = null;
	/**底部止损止盈视图*/
	@BindView(R.id.bottom_view)
	OrderBottomView mBottomview;
	@BindView(R.id.morder_title_price)
	TitleRangeView mPriceTitleView;
	@BindView(R.id.morder_title_lot)
	TitleRangeView mLotTitleView;
	/** 保证金 */
	@BindView(R.id.margin_view)
	TextView mMarginView;

	/**产品弹层*/
	private TradeProductPopWindow mProPopwindow;
	/**下单类型弹层*/
	private TradeTypePopWindow mTypePop;
	/**有效期类型弹层*/
	private TradeTypePopWindow mExpireTypePop;
	/**下单类型数据*/
	private String[] mStringArray;
	/**有效期类型数据*/
	private String[] mExpireStringArray;

	/**输入的挂单价*/
	private String mInputPrice = "";
	/**挂单类型*/
	private int priceType = AppContances.ORDER_TYPE_APPLY_TYPE;
	/**有效期类型*/
	private int expireType = AppContances.VALID_TYPE_WEEK;

	/**保证金逻辑处理对象*/
	private TradePresenter mPresenter;

	/**
	 * 更新通知处理
	 */
	private final Handler HandlerCallback = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case GTSConst.REPLY_SYMBOL_TICK_UPDATE:
				//更新界面价格和范围值
				updateWithPrice();
				onConfigDynamicViews();
				mBottomview.updateProduct(mRangeModel);
				checkError();
				break;
			case AppContances.HANDLER_SCR_UPDATE_INPUTPRICE:
				TradeBusiness.calPendingLossAndWin(mTickModel,mSymbolModel, mRangeModel,mInputPrice, mTradeDir, priceType);
				mBottomview.updateProduct(mRangeModel);
				checkError();
				break;
			case GTSConst.REPLY_SYMBOL_UPDATE:
				if(null != mProPopwindow){
					mProPopwindow.refreshData();
				}
				if(null != m_lotEditView){
					setMarginView(m_lotEditView.getFloatValue());
				}
				break;
			}
		}
	};

	@Override
	public void setArguments(Bundle args) {
		super.setArguments(args);
		if (args != null) {
			int zoneType = args.getInt("zoneType");
			mUiCode = args.getInt("uiCode");
			mTradeDir = args.getInt("orderDir", AppContances.TRADE_TYPE_BUY);
			mTickModel = DataManager.instance().getTickModel(mUiCode);
			if(null == mTickModel){
				if (null != getActivity()) {
					getActivity().finish();
				}
				Logger.e("mTickModel对象为空，出现异常");
				return;
			}
			setProductInfo();
		}
	}

	@Override
	protected int getLayoutId() {
		return R.layout.fragment_order_create_apply;
	}

	@Override
	protected void initLayoutView() {
		super.initLayoutView();
		mPrdNameLayout.setSelected(false);
		typeView.setText(AppMain.getAppString(R.string.order_limit_price));
		typeLayout.setSelected(false);

		mPriceTitleView.setTitleView(R.string.order_title_price);
		mLotTitleView.setTitleView(R.string.order_title_lot);
		m_priceEditView.setLongClickable(false);
		m_lotEditView.setLongClickable(false);
		m_priceEditView.setAfterTextChangedListener(mTextChangedListener);
		m_lotEditView.setAfterTextChangedListener(mTextChangedListener);
		m_lotEditView.getNumericInput().setOnFocusChangeListener(this);
		m_priceEditView.getNumericInput().setOnFocusChangeListener(this);

		expireTypeView.setText(AppMain.getAppString(R.string.order_item_trade_expiry_week));
		expireTypeLayout.setSelected(false);

		if (mTradeDir == AppContances.TRADE_TYPE_BUY) {
			m_buyLayout.setSelected(true);
			m_sellLayout.setSelected(false);
		} else {
			m_buyLayout.setSelected(false);
			m_sellLayout.setSelected(true);
		}

		mBottomview.setPriceType(false);
		mBottomview.setFoldView(false);
		mBottomview.setFocusChange(this);
		mBottomview.setErrorCheckLisenter(new OrderBottomView.onErrorCheckLisenter() {

			@Override
			public void onErrorCheck() {
				checkError();
			}
		});

		mPositionModel =  new DataItemDetail();
		cmd = AppContances.ORDER_TYPE_APPLY;
		mRangeModel = new TradeRangeModel();
		mPresenter = new TradePresenter(mUiCode);
	}

	@Override
	protected void initViewData() {
		mPrdNameView.setText(mSymbol);
		TradeBusiness.calPendingLossAndWin(mTickModel,mSymbolModel, mRangeModel,mInputPrice, mTradeDir, priceType);
		updateWithPrice();
		onConfigDynamicViews();
		m_lotEditView.setText(DoubleConverter.toStringData(mCurLot, 2));
		m_priceEditView.setText(mRangeModel.defalutPrice);
		mBottomview.setProductInfo(mRangeModel);
	}

	private void setProductInfo(){
		if(null != TradeOrderActivity.mInstance ){
			TradeOrderActivity.mInstance.mUiCode = mTickModel.getInt(GTSConst.JSON_KEY_CODEID);
		}
		mSymbol = DataManager.instance().getPrdName(mTickModel);
		mUiCode = mTickModel.getInt(GTSConst.JSON_KEY_CODEID);
		zoneId = mTickModel.getInt(GTSConst.JSON_KEY_ZONE);
		updateSymbolModel();
		mCurLot = GTConfig.instance().getProductOrderLot(mUiCode,mSymbolModel.getString(GTSConst.JSON_KEY_DEFAULTOT));
	}

	@Override
	public void registerRxBus() {
		Disposable marginRegister = RxBus.getInstance().register(GTSConst.REPLY_MARGIN_UPDATE+"", Bundle.class).observeOn(AndroidSchedulers.mainThread())
				.subscribe(new Consumer<Bundle>(){

					@Override
					public void accept(@NonNull Bundle bundle) throws Exception {
						if(null != bundle){
							onMarginNotify(bundle.getInt("iNotification"));
						}
					}
				});

		bindSubscription(marginRegister);

		Disposable positionListRegister = RxBus.getInstance().registertoObservableSticky(GTSConst.REPLY_POSTION_LIST+"", Bundle.class).observeOn(AndroidSchedulers.mainThread())
				.subscribe(new Consumer<Bundle>(){

					@Override
					public void accept(@NonNull Bundle bundle) throws Exception {
						if(null != mPresenter){
							setMarginView(m_lotEditView.getFloatValue());
						}
					}
				});
		bindSubscription(positionListRegister);
	}

	/**
	 * 设置界面加减器中各属性值
	 */
	private void onConfigDynamicViews() {
		if (null == mSymbolModel) {
			return;
		}
		// 设置手数
		m_lotEditView.setMax(DoubleConverter.toDoubleData(mSymbolModel.getString(GTSConst.JSON_KEY_VOLUMESMAX)));
		m_lotEditView.setMin(DoubleConverter.toDoubleData(mSymbolModel.getString(GTSConst.JSON_KEY_VOLUMESMIN)));
		m_lotEditView.setMinSteps(DoubleConverter.toDoubleData(mSymbolModel.getString(GTSConst.JSON_KEY_VOLUMESSTEP)));
		m_lotEditView.setDigits(mSymbolModel.getString(GTSConst.JSON_KEY_VOLUMESMAX));
		mLotTitleView.setRangeView(AppMain.getAppString(R.string.order_hint_lot, mSymbolModel.getString(GTSConst.JSON_KEY_VOLUMESMIN)), AppMain.getAppString(R.string.order_hint_lot, mSymbolModel.getString(GTSConst.JSON_KEY_VOLUMESMAX)));
		mPriceTitleView.setRangeView(mRangeModel.minRangePrice, mRangeModel.maxRangePrice);
		m_priceEditView.setMinSteps(mRangeModel.pointToPrice);
		m_priceEditView.setMin(Double.MIN_VALUE);
		m_priceEditView.setMax(Double.MAX_VALUE);
		m_priceEditView.setDigits(10, (9-mRangeModel.mDigit), mRangeModel.mDigit);
		m_priceEditView.setDefalutValue(mRangeModel.defalutPrice);
	}

	/**
	 * 切换产品
	 *
	 */
	private void changeProduct(DataItemDetail tickModel) {
		if(null != tickModel){
			mTickModel = tickModel;
			updateSymbolModel();
			//发送自选股请求
			AppTerminal.instance().sendQuoteSubscribe(DataManager.instance().getQuoteSubscribeCode(mTickModel.getInt(GTSConst.JSON_KEY_CODEID)));
			setProductInfo();
			initViewData();
			if(null != mPresenter){
				mPresenter.setMarginLevel(mUiCode);
				setMarginView(m_lotEditView.getFloatValue());
			}
		}
	}

	/**
	 * 显示选择产品类型pop
	 */
	private void showProPop() {
		if (null == mProPopwindow) {
			mProPopwindow = new TradeProductPopWindow(getActivity(), mPrdNameLayout, AppMain.getAppString(R.string.order_product), mUiCode, zoneId, new TradeProductPopWindow.RecyclerItemClickListener() {
				@Override
				public void onClick(DataItemDetail model) {
					mPrdNameLayout.setSelected(false);
					changeProduct(model);
				}
			});
		}
		mProPopwindow.show();
	}

	/**
	 * 显示下单类型pop
	 */
	private void showTypePop() {
		if (null == mTypePop) {
			mStringArray = getActivity().getResources().getStringArray(R.array.trade_type_list);
			mTypePop = new TradeTypePopWindow(getActivity(), typeLayout, AppMain.getAppString(R.string.order_type), 0, mStringArray, new RecyclerClickListener() {
				@Override
				public void onClick(int position, DataItemDetail itemDetail) {
					String value = mStringArray[position];
					if (0 == position) {
						priceType = AppContances.ORDER_TYPE_APPLY_TYPE;
					} else {
						priceType = AppContances.ORDER_TYPE_APPLY_STOP_TYPE;
					}
					typeView.setText(value);
					typeLayout.setSelected(false);
					TradeBusiness.calPendingLossAndWin(mTickModel, mSymbolModel,mRangeModel,mInputPrice, mTradeDir, priceType);
					onConfigDynamicViews();
					m_priceEditView.setText(mRangeModel.defalutPrice);
					mBottomview.setProductInfo(mRangeModel);
				}
			});
			mTypePop.popWindow.setBackgroundDrawable(new BitmapDrawable(AppMain.getApp().getResources(), (Bitmap) null));
		}
		mTypePop.show();
	}

	/**
	 * 显示pop
	 */
	private void showExpirePop() {
		if (null == mExpireTypePop) {
			mExpireStringArray = getActivity().getResources().getStringArray(R.array.expire_type_list);
			mExpireTypePop = new TradeTypePopWindow(getActivity(), expireTypeLayout, AppMain.getAppString(R.string.order_expire), 1, mExpireStringArray, new RecyclerClickListener() {
				@Override
				public void onClick(int position, DataItemDetail itemDetail) {
					String value = mExpireStringArray[position];
					if (0 == position) {
						expireType = AppContances.VALID_TYPE_DAY;
					} else {
						expireType = AppContances.VALID_TYPE_WEEK;
					}
					expireTypeView.setText(value);
					expireTypeLayout.setSelected(false);
				}
			});
		}
		mExpireTypePop.show();
	}

	/**
	 * 设置初始保证金值
	 * @param lot
	 */
	private void setMarginView(float lot){
		if(null != mMarginView && null != mSymbolModel && null != mPresenter){
			mMarginView.setText(mPresenter.calLevelMargin(lot, DoubleConverter.toFloatData(mSymbolModel.getString(GTSConst.JSON_KEY_MARGININITIAL)), mTradeDir));
		}
	}

	@Override
	public void onHiddenChanged(boolean hidden) {
		super.onHiddenChanged(hidden);
		if (!hidden) {
			if (null != TradeOrderActivity.mInstance && TradeOrderActivity.mInstance.hasChangeLot) {
				if (null != TradeOrderActivity.mInstance && TradeOrderActivity.mInstance.hasChangeLot) {
					mCurLot = GTConfig.instance().getProductOrderLot(mUiCode, mSymbolModel.getString(GTSConst.JSON_KEY_DEFAULTOT));
					if (null != m_lotEditView) {
						m_lotEditView.setText(DoubleConverter.toStringData(mCurLot, 2));
					}
				}
			}

			if (null != TradeOrderActivity.mInstance && mUiCode != TradeOrderActivity.mInstance.mUiCode) {
				mUiCode = TradeOrderActivity.mInstance.mUiCode;
				if(null != mProPopwindow){
					mProPopwindow.refreshData(mUiCode);
				}
				DataItemDetail mData = DataManager.instance().getTickModel(mUiCode);
				changeProduct(mData);
			}

			if (null != TradeOrderActivity.mInstance && mTradeDir != TradeOrderActivity.mInstance.mTradeDir) {
				changeTradeDir(TradeOrderActivity.mInstance.mTradeDir);
			}

			checkError();
		}
	}

	/**
	* 输入框文本变化处理
	*/
	private final NumberInput.OnTextChangedListener mTextChangedListener = new NumberInput.OnTextChangedListener() {
		@Override
		public void onTextChanged(EditText edit, Editable s) {

			if (TextUtils.isEmpty(edit.getText()) && null != mBottomview) {
//				mBottomview.morder_loss_range.setText("[0-0]");
//				mBottomview.morder_win_range.setText("[0-0]");
			}
			if (edit == m_priceEditView.getNumericInput()) {
				mInputPrice = m_priceEditView.getValueString();
				if (HandlerCallback != null) {
					HandlerCallback.sendEmptyMessage(AppContances.HANDLER_SCR_UPDATE_INPUTPRICE);
				}
			}else if(edit == m_lotEditView.getNumericInput()){
				setMarginView(m_lotEditView.getNumericInput().getFloatValue());
			}

			checkError();
		}
	};

	@Override
	public void onFocusChange(View v, boolean hasFocus) {
		mBottomview.onFocusChanged(v, hasFocus);

		checkError();
	}

	/**
	 * 检查界面错误
	 * @return
	 */
	private boolean checkError() {
		String errorMessage = "";

		//挂单价格
		String rangePrice = m_priceEditView.getText();
		String errorMessage1 = TradeBusiness.getApplyPriceErrorMsg(mRangeModel.minRangePrice, mRangeModel.maxRangePrice, rangePrice);
		if (!"".equals(errorMessage1)) {
			mPriceTitleView.setErrorColor();
			errorMessage = errorMessage1;
		}else{
			mPriceTitleView.setDefalutColor();
		}

		// 手数
		String lot = m_lotEditView.getText();
		String errorMessage2 = TradeBusiness.getLotErrorMsg(mSymbolModel.getString(GTSConst.JSON_KEY_VOLUMESMIN),
				mSymbolModel.getString(GTSConst.JSON_KEY_VOLUMESMAX), mSymbolModel.getString(GTSConst.JSON_KEY_VOLUMESSTEP), lot);
		if (!"".equals(errorMessage2)) {
			mLotTitleView.setErrorColor();
			if ("".equals(errorMessage)) {
				errorMessage = errorMessage2;
			}
		}else{
			mLotTitleView.setDefalutColor();
		}

		//检查止损止盈
		String errorMessage3 = mBottomview.checkError();
		if (!"".equals(errorMessage3) && "".equals(errorMessage)) {
			errorMessage = errorMessage3;
		}

		if (isVisible() && null != mStatusListener) {
			mStatusListener.onError(errorMessage);
		}

		if(!"".equals(errorMessage)) {
			return true;
		}else {
			return false;
		}
	}

	@OnClick(R.id.sell_price_layout)
	void changeSellDir(){
		changeTradeDir(AppContances.TRADE_TYPE_SALE);
	}

	@OnClick(R.id.buy_price_layout)
	void changeBuyDir(){
		changeTradeDir(AppContances.TRADE_TYPE_BUY);
	}

	/**
	 * 买卖方向切换
	 * @param tradeDir
	 */
	private void changeTradeDir(int tradeDir) {
		mTradeDir = tradeDir;
		if(null != TradeOrderActivity.mInstance ){
			TradeOrderActivity.mInstance.mTradeDir = tradeDir;
		}
		if (mTradeDir == AppContances.TRADE_TYPE_SALE) {
			m_buyLayout.setSelected(false);
			m_sellLayout.setSelected(true);
		} else {
			m_buyLayout.setSelected(true);
			m_sellLayout.setSelected(false);
		}
		TradeBusiness.calPendingLossAndWin(mTickModel,mSymbolModel, mRangeModel,mInputPrice, mTradeDir, priceType);
		onConfigDynamicViews();
		m_priceEditView.setText(mRangeModel.defalutPrice);
		mBottomview.setProductInfo(mRangeModel);
		setMarginView(m_lotEditView.getFloatValue());
	}

	@OnClick(R.id.proNameView)
	void selectProduct(){
		//isSelected标识之前的状态，之前为true收起来，之前为false展开
		if (mPrdNameLayout.isSelected()) {
			mPrdNameLayout.setSelected(false);
			if (null != mProPopwindow) {
				mProPopwindow.hidden();
			}
		} else {
			mPrdNameLayout.setSelected(true);
			showProPop();
		}
	}

	@OnClick(R.id.trade_type_Layout)
	void changeTradeType(){
		if (typeLayout.isSelected()) {
			typeLayout.setSelected(false);
			if (null != mTypePop) {
				mTypePop.hidden();
			}
		} else {
			typeLayout.setSelected(true);
			showTypePop();
		}
	}

	@OnClick(R.id.expire_typeLayout)
	void changeTradeExpire(){
		if (expireTypeLayout.isSelected()) {
			expireTypeLayout.setSelected(false);
			if (null != mExpireTypePop) {
				mExpireTypePop.hidden();
			}
		} else {
			expireTypeLayout.setSelected(true);
			showExpirePop();
		}
	}

	@Override
	public boolean hasPostData() {
		Logger.e("挂单价范围 ： " + mRangeModel.minRangePrice + "," + mRangeModel.maxRangePrice +"," + m_priceEditView.getText());
		if (checkError()) {
			return false;
		}

		if (!TradeBusiness.PreOrderCheck(getActivity(), mTickModel.getInt(GTSConst.JSON_KEY_ZONE), mTickModel.getInt(GTSConst.JSON_KEY_TRADESTATE), true)) {
			return false;
		}

		try {
			mSeq = GTSDataListener.curSeq++;
			GTSDataListener.instance().addSeqList(mSeq+"", cmd+"");
			Logger.e("挂单下单的seq == " + mSeq);
			jsonData.put(GTSConst.JSON_KEY_CODEID, mUiCode);
			jsonData.put(GTSConst.JSON_KEY_ORDERPRICE, m_priceEditView.getText());
			jsonData.put(GTSConst.JSON_KEY_DIRECTION, mTradeDir);
			jsonData.put(GTSConst.JSON_KEY_EXPIRETYPE, expireType);
			jsonData.put(GTSConst.JSON_KEY_RANGE, mSymbolModel.getString(GTSConst.JSON_KEY_RANGE));
			jsonData.put(GTSConst.JSON_KEY_VOLUME, DoubleConverter.toStringData(m_lotEditView.getText(), 2));
			jsonData.put(GTSConst.JSON_KEY_ORDERTYPE, priceType);
			jsonData.put(GTSConst.JSON_KEY_USEDIP,0);
			jsonData.put(GTSConst.JSON_KEY_STOPLOSS, mBottomview.getLossPrice());
			jsonData.put(GTSConst.JSON_KEY_STOPPROFIT, mBottomview.getWinPrice());
			jsonData.put(GTSConst.JSON_KEY_TRADE_SEQ, mSeq);
		}catch (JSONException e){
			e.printStackTrace();
		}

		if (!DoubleConverter.isZero(DoubleConverter.toFloatData(jsonData.optString(GTSConst.JSON_KEY_STOPLOSS)))) {
			mDetail.setStringValue("mLoss", jsonData.optString(GTSConst.JSON_KEY_STOPLOSS));
		} else {
			mDetail.setStringValue("mLoss", "");
		}
		if (!DoubleConverter.isZero(DoubleConverter.toFloatData(jsonData.optString(GTSConst.JSON_KEY_STOPPROFIT)))) {
			mDetail.setStringValue("mWin",jsonData.optString(GTSConst.JSON_KEY_STOPPROFIT));
		} else {
			mDetail.setStringValue("mWin", "");
		}

		mDetail.setStringValue("mCurrentTag", AppContances.TAB_ID_PENDING_ORDER);
		mDetail.setStringValue("mSymbol", mSymbol);
		mDetail.setIntValue("mPrdCode", mUiCode);
		mDetail.setIntValue("mTradeDir", mTradeDir);
		mDetail.setStringValue("mCurLot",jsonData.optString(GTSConst.JSON_KEY_VOLUME));
		mDetail.setStringValue("mPrice", m_priceEditView.getText());

		return true;
	}

	@Override
	public void requstData() {
		int result = AppTerminal.instance().reqOrder(cmd, jsonData.toString());
		if(result != 0){
			if(null != mStatusListener){
				mStatusListener.onFail();
			}
			PopupConfirmDialog.NotifyPrompt(getActivity(), ConfigUtil.instance().mErrorConfigObject.optString(ConfigType.SERVER_ERROR_1016));
		}
	}

	@Override
	public void onSymbolNotify(DataItemDetail tickModel) {
		super.onSymbolNotify(tickModel);
		if(null != tickModel){
			if(mUiCode == tickModel.getInt(GTSConst.JSON_KEY_CODEID)){
				mTickModel = tickModel;
				if(null != mRangeModel){
					TradeBusiness.calPendingLossAndWin(mTickModel, mSymbolModel,mRangeModel,mInputPrice, mTradeDir, priceType);
					HandlerCallback.sendEmptyMessage(GTSConst.REPLY_SYMBOL_TICK_UPDATE);
				}
			}else{
				if(null != mPresenter){
					setMarginView(m_lotEditView.getFloatValue());
				}
			}
		}
	}

	@Override
	public void onSymbolNotify() {
		super.onSymbolNotify();
		updateSymbolModel();
		HandlerCallback.sendEmptyMessage(GTSConst.REPLY_SYMBOL_UPDATE);
	}

	@Override
	public void onMarginNotify(int mSwitch) {
		if(null != mPresenter){
			mPresenter.setMarginLevel(mUiCode);
			setMarginView(m_lotEditView.getFloatValue());
		}
	}

	@Override
	public void onOrderSuccessNotify(int notifyId, int orderId, DataItemDetail model) {
		if (mSeq == notifyId) {
			Logger.e("挂单下单成功后  orderId = " + orderId + " mSeq == " + mSeq);
			if (null != model) {
				mDetail.setIntValue("mOrderID", orderId);
				mDetail.setStringValue("mPrice",model.getString(GTSConst.JSON_KEY_ORDERPRICE));
				mDetail.setIntValue("mType",model.getInt(GTSConst.JSON_KEY_ORDERTYPE));
				mDetail.setStringValue("mTime", StringFormatter.instance().secToDateTime(model.getInt(GTSConst.JSON_KEY_TIME)));
				if (!DoubleConverter.isZero(DoubleConverter.toFloatData(model.getString(GTSConst.JSON_KEY_STOPLOSS)))) {
					mDetail.setStringValue("mLoss", model.getString(GTSConst.JSON_KEY_STOPLOSS));
				} else {
					mDetail.setStringValue("mLoss", "");
				}
				if (!DoubleConverter.isZero(DoubleConverter.toFloatData(model.getString(GTSConst.JSON_KEY_STOPPROFIT)))) {
					mDetail.setStringValue("mWin",model.getString(GTSConst.JSON_KEY_STOPPROFIT));
				} else {
					mDetail.setStringValue("mWin", "");
				}
				if (null != mStatusListener) {
					Logger.e("onOrderSuccessNotify mStatusListener 挂单下单成功后  orderId = "
							+ orderId);
					mStatusListener.onSuc(mDetail);
				}
			}
		}
	}

	@Override
	public void onDetach() {
		super.onDetach();
		if(null != mProPopwindow){
			mProPopwindow.hidden();
		}

		if(null != mTypePop){
			mTypePop.hidden();
		}

		if(null != mExpireTypePop){
			mExpireTypePop.hidden();
		}
	}

}